package com.douziit.meilianoa.base.response;

import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * @author MrShun
 * @version 1.0
 * @Date 2017/11/14
 */
public class Page<T> {

    /**
     * 当前第几页
     */
    private Integer index = 0;

    /**
     * 每页大小
     */
    private Integer size = 10;

    /**
     * 数据对象
     */
    private List<T> data;

    /**
     * 总记录数
     */
    private Long total;

    /**
     * 总页数
     */
    private Integer pages;

    public Page() {
    }

    public Page(int index, int size, List<T> data, long total, int pages) {
        this.index = index;
        this.size = size;
        this.data = data;
        this.total = total;
        this.pages = pages;
    }

    public Page(List<T> obj) {
        if (obj instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page page = (com.github.pagehelper.Page) obj;
            this.index = page.getPageNum();
            this.size = page.getPageSize();
            this.data = page.getResult();
            this.total = page.getTotal();
            this.pages = page.getPages();
        }
    }

    public Page(PageInfo page) {
        this.index = page.getPageNum();
        this.size = page.getPageSize();
        this.data = page.getList();
        this.total = page.getTotal();
        this.pages = page.getPages();
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Integer getPages() {
        return pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }
}
